package com.example.safeassistan.home.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.example.safeassistan.R;
import com.example.safeassistan.UserInfoModel;
import com.example.safeassistan.base.BaseActivity;
import com.example.safeassistan.base.BaseModel;
import com.example.safeassistan.common.UserData;
import com.example.safeassistan.constants.UrlConstants;
import com.example.safeassistan.hiddendanger.activity.HiddenDangerImageAdapter;
import com.example.safeassistan.hiddendanger.activity.HiddendangerAssess;
import com.example.safeassistan.hiddendanger.activity.HiddendangerUnSubmit;
import com.example.safeassistan.http.HttpRequest;
import com.example.safeassistan.http.HttpStringCallBack;
import com.example.safeassistan.main.MainActivity;
import com.example.safeassistan.utile.GlideEngine;
import com.example.safeassistan.utile.JsonUtils;
import com.example.safeassistan.utile.ToastUtil;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class HiddenDangerAdd extends BaseActivity implements View.OnClickListener {
    private LinearLayout llReformInfo,llHiddenDangerInfo;
    private TextView tvGetPast,tvNoGetPast,tvHiddendDanger,tvNoRelative
            ,tvSubmit,tvHiddendDangerName,tvHiddendDangerType,tvHiddendDangerLevel,
            tvAssessPerson,tvAsseessDepart,tvReformDate;
    private EditText etRemark,etDataCollect,etHiddenTitle;
    private LinearLayout llHiddendangerType,llAsseessDepart,llAssessPerson,llReformDate,
            llHiddenLevel;

    private LinearLayout llReformDepart,llReformPerson,llAcceptDepart,llAcceptPerson,llReformDate1,llReform;
    private TextView tvReformDepart,tvReformPerson,tvAcceptDepart,tvAcceptPerson,tvReformDate1;

    private RecyclerView rcPic;
    private int type=0;//类型 0 通过 1不通过 2 存在隐患 3不涉及 4 未处理

    private static final Integer REQUESTCODE=10001;
    private static final Integer REQUESTCODE2=10002;
    private static final Integer REQUESTCODE1=10000;
    private static final Integer REQUESTCODE3=10003;
    private static final Integer REQUESTCODE4=10004;
    private static final Integer REQUESTCODE5=10005;
    private static final Integer REQUESTCODE6=10006;
    private static final Integer REQUESTCODE7=10007;


    private String checkTableId="";//检查表id
    private String defRecordId="";//检查记录表id
    private String hdangerLevel="";//	隐患等级 1->重大,3->一般
    private String hdangerTitle="";//隐患标题
    private String reviewDepartId="";//评审部门
    private String reviewPersonId="";//评审人员
    private String reviewTime="";//评审日期
    private String riskPointId="";//风险点id
    private String remark="";//备注
    private String itemImg="";//图片
    private String itemId="";//检查项id
    private String hdangerType="";//隐患类型
    private String dataCollect="";//	数据采集
    private String rectDepartId="";//整改部门id
    private String rectPersonId="";//整改人员id
    private String acceptDepartId="";//验收部门id
    private String acceptPersonId="";//验收人员id
    private String allottedTime="";//整改期限

    private String name="";
    private String checkAddress="";


    private HiddenDangerImageAdapter adapter;
    private ArrayList<String> imagesUrl;
    private RecyclerView.LayoutManager managers;


    public static void actionStart(Context context,String itemId,String riskPointId,String checkTableId,String defRecordId) {
        Intent intent = new Intent(context, HiddenDangerAdd.class);
        intent.putExtra("itemId",itemId);
        intent.putExtra("riskPointId",riskPointId);
        intent.putExtra("checkTableId",checkTableId);
        intent.putExtra("defRecordId",defRecordId);
        context.startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.llReformPerson:
                //整改人
                if (rectDepartId.equals("")){
                    Toast.makeText(HiddenDangerAdd.this,"请先选择整改部门!!!",Toast.LENGTH_SHORT).show();
                    return;
                }else {
                    Intent intent5=new Intent(HiddenDangerAdd.this, AuthorizeDepartMentPerson.class);
                    intent5.putExtra("flag", REQUESTCODE5);
                    intent5.putExtra("defectId",rectDepartId);
                    startActivityForResult(intent5, REQUESTCODE5);
                }
                break;
            case R.id.llAcceptPerson:
                //验收人
                if (acceptDepartId.equals("")){
                    Toast.makeText(HiddenDangerAdd.this,"请先选择验收部门!!!",Toast.LENGTH_SHORT).show();
                    return;
                }else {
                    Intent intent7=new Intent(HiddenDangerAdd.this, AuthorizeDepartMentPerson.class);
                    intent7.putExtra("flag", REQUESTCODE7);
                    intent7.putExtra("defectId",rectDepartId);
                    startActivityForResult(intent7, REQUESTCODE7);
                }
                break;

            case R.id.llReformDate1:
                //整改日期
                TimePickerView startTime1 = new TimePickerBuilder(HiddenDangerAdd.this, new OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {//选中事件回调
                        Calendar calendar=Calendar.getInstance();
                        calendar.setTime(date);
                        SimpleDateFormat sf=new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
                        allottedTime=sf.format(date);
                        tvReformDate1.setText(sf.format(date));
                    }
                })
                        .setType(new boolean[]{true, true, true, false, false, false})// 默认全部显示
                        .setCancelText("取消")//取消按钮文字
                        .isDialog(true)
                        .setSubmitText("确定")//确认按钮文字
                        .setTitleSize(18)//标题文字大小
                        .setTitleColor(getResources().getColor(R.color.white))
                        .setTitleText("整改日期")
                        .setContentTextSize(17)
                        .setOutSideCancelable(true)//点击屏幕，点在控件外部范围时，是否取消显示
                        .isCyclic(true)//是否循环滚动
                        .setTextColorOut(getResources().getColor(R.color.gray6))
                        .setTextColorCenter(getResources().getColor(R.color.blue_3B5BEA))
                        .setSubmitColor(getResources().getColor(R.color.white))//确定按钮文字颜色
                        .setLabel("年", "月", "日", "时", "分", "秒")//默认设���为年月日时分秒
                        .isCenterLabel(false) //是否只显示中间选中项的 label 文字，false 则每项 item 全部都带有 label。
                        .build();
                startTime1.show();
                break;
            case R.id.llHiddendangerType:
                //隐患类型
                Intent intent1=new Intent(HiddenDangerAdd.this, ActivityHiddenDangerType.class);
                intent1.putExtra("flag", REQUESTCODE3);
                startActivityForResult(intent1, REQUESTCODE3);
                break;
            case R.id.llHiddenLevel:
                //隐患等级
                //隐患等级
                Intent intent2=new Intent(HiddenDangerAdd.this, HiddenDanger_Level_Select.class);
                intent2.putExtra("flag", REQUESTCODE2);
                startActivityForResult(intent2, REQUESTCODE2);
                break;
            case R.id.tvGetPast:
                //通过
                type=0;
                reSetStatus();
                llReform.setVisibility(View.GONE);
                llReformInfo.setVisibility(View.GONE);
                tvGetPast.setTextColor(getResources().getColor(R.color.blue_3B5BEA));
                tvGetPast.setBackgroundResource(R.drawable.blue_bg_3_selecter_selected);
                break;
            case R.id.tvNoGetPast:
                //不通过
                type=1;
                reSetStatus();
                llReform.setVisibility(View.GONE);
                llReformInfo.setVisibility(View.GONE);
                tvNoGetPast.setTextColor(getResources().getColor(R.color.blue_3B5BEA));
                tvNoGetPast.setBackgroundResource(R.drawable.blue_bg_3_selecter_selected);
                break;
            case R.id.tvHiddendDanger:
                //存在隐患
                type=2;
                reSetStatus();
                tvHiddendDanger.setTextColor(getResources().getColor(R.color.blue_3B5BEA));
                tvHiddendDanger.setBackgroundResource(R.drawable.blue_bg_3_selecter_selected);
                llHiddenDangerInfo.setVisibility(View.VISIBLE);
                if (UserData.create(HiddenDangerAdd.this).get(UserData.ls_ps).equals("0")){
                    llReformInfo.setVisibility(View.GONE);
                    llReform.setVisibility(View.VISIBLE);
                }else {
                    llReformInfo.setVisibility(View.VISIBLE);
                    llReform.setVisibility(View.GONE);
                }

                break;
            case R.id.tvNoRelative:
                //不涉及
                type=3;
                reSetStatus();
                llReform.setVisibility(View.GONE);
                llReformInfo.setVisibility(View.GONE);
                tvNoRelative.setTextColor(getResources().getColor(R.color.blue_3B5BEA));
                tvNoRelative.setBackgroundResource(R.drawable.blue_bg_3_selecter_selected);
                break;
            case R.id.tvSubmit:
                //提交
                if (type==2){
                    if (imagesUrl.size()<1){
                        Toast.makeText(HiddenDangerAdd.this,"请上传至少一张附件",Toast.LENGTH_SHORT).show();
                        return;
                    }
                }

                if (type==2){
                    if (itemImg.contains("shaungyufang.oss-cn-beijing.aliyuncs.com")){
                        submitData();
                    }else {
                        uploadImg(imagesUrl.get(0));
                    }
                }else {
                    if (imagesUrl.size()>0){
                        uploadImg(imagesUrl.get(0));
                    }else {
                        submitData();
                    }
                }

                break;
            case R.id.llAsseessDepart:
                Intent intent=new Intent(HiddenDangerAdd.this, AuthorizeDepartment.class);
                intent.putExtra("flag", REQUESTCODE);
                startActivityForResult(intent, REQUESTCODE);
                break;
            case R.id.llReformDepart:
                //整改部门
                Intent intent4=new Intent(HiddenDangerAdd.this, AuthorizeDepartment.class);
                intent4.putExtra("flag", REQUESTCODE4);
                startActivityForResult(intent4, REQUESTCODE4);
                break;
            case R.id.llAcceptDepart:
                //验收部门
                Intent intent6=new Intent(HiddenDangerAdd.this, AuthorizeDepartment.class);
                intent6.putExtra("flag", REQUESTCODE6);
                startActivityForResult(intent6, REQUESTCODE6);
                break;

            case R.id.llAssessPerson:
                //评审人
                if (reviewDepartId.equals("")){
                    //没有选择评审部门
                    Toast.makeText(HiddenDangerAdd.this,"请先选择评审部门!!!",Toast.LENGTH_SHORT).show();
                    return;
                }else {
                    Intent intent3=new Intent(HiddenDangerAdd.this, AuthorizeDepartMentPerson.class);
                    intent3.putExtra("flag", REQUESTCODE1);
                    intent3.putExtra("defectId",reviewDepartId);
                    startActivityForResult(intent3, REQUESTCODE1);
                }
                break;
            case R.id.llReformDate:
                TimePickerView startTime = new TimePickerBuilder(HiddenDangerAdd.this, new OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {//选中事件回调
                        Calendar calendar=Calendar.getInstance();
                        calendar.setTime(date);
                        SimpleDateFormat sf=new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
                        reviewTime=sf.format(date);
                        tvReformDate.setText(sf.format(date));
                    }
                })
                        .setType(new boolean[]{true, true, true, false, false, false})// 默认全部显示
                        .setCancelText("取消")//取消按钮文字
                        .isDialog(true)
                        .setSubmitText("确定")//确认按钮文字
                        .setTitleSize(18)//标题文字大小
                        .setTitleColor(getResources().getColor(R.color.white))
                        .setTitleText("整改日期")
                        .setContentTextSize(17)
                        .setOutSideCancelable(true)//点击屏幕，点在控件外部范围时，是否取消显示
                        .isCyclic(true)//是否循环滚动
                        .setTextColorOut(getResources().getColor(R.color.gray6))
                        .setTextColorCenter(getResources().getColor(R.color.blue_3B5BEA))
                        .setSubmitColor(getResources().getColor(R.color.white))//确定按钮文字颜色
                        .setLabel("年", "月", "日", "时", "分", "秒")//默认设���为年月日时分秒
                        .isCenterLabel(false) //是否只显示中间选中项的 label 文字，false 则每项 item 全部都带有 label。
                        .build();
                startTime.show();
                break;
        }
    }

    public  void getUserInfo() {
        new HttpRequest(HiddenDangerAdd.this).doGet(UrlConstants.userInfoqueryPersonage, null,new HttpStringCallBack() {
            @Override
            public void onSuccess(Object result) {
                try {
                    String data = result.toString();
                    //把请求得数据转换成json对象
                    JSONObject jsonObject = null;
                    jsonObject = new JSONObject(data);
                    String message = jsonObject.getString("message");
                    Boolean success=jsonObject.getBoolean("success");
                    if(success){
                        Object obj = JsonUtils.fromJson(result.toString(), UserInfoModel.class);
                        if (obj instanceof UserInfoModel) {
                            UserInfoModel model = (UserInfoModel) obj;
                            UserData.create(HiddenDangerAdd.this).saveUserData(model.getResult());
                        }
                    }else {
                        Toast.makeText(HiddenDangerAdd.this,message,Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int code, String msg) { }
        });
    }

    public void uploadImg(String path){
        new HttpRequest(HiddenDangerAdd.this).doUploadFile(UrlConstants.commonupload, "", "file", new File(path), new HttpStringCallBack() {
            @RequiresApi(api = Build.VERSION_CODES.M)
            @Override
            public void onSuccess(Object result) {
                String datas = result.toString();
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject(datas);
                    String message = jsonObject.getString("message");
                    Boolean success = jsonObject.getBoolean("success");
                    if (success) {
                        Object obj = JsonUtils.fromJson(result.toString(), BaseModel.class);
                        if (obj instanceof BaseModel) {
                            BaseModel model=(BaseModel) obj;
                            imagesUrl.remove(0);
                            itemImg=itemImg+model.getMessage()+",";
                            Iterator<String> iterator=imagesUrl.iterator();
                            if (iterator.hasNext()){
                                uploadImg(iterator.next());
                            }else {
                                submitData();
                            }
                        }else {
                            ToastUtil toastUtil = new ToastUtil(getContext(), R.layout.popu_success1, message, 1);
                            toastUtil.show();
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int code, String msg) { }
        });
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.hiddendanger_add_home_backlog;
    }

    @Override
    protected void initView() {
        setTitleText("添加隐患");
        name=getIntent().getStringExtra("name");
        itemId=getIntent().getStringExtra("itemId");
        checkTableId=getIntent().getStringExtra("checkTableId");
        defRecordId=getIntent().getStringExtra("defRecordId");
        riskPointId=getIntent().getStringExtra("riskPointId");
        checkAddress=getIntent().getStringExtra("checkAddress");
        llReformInfo=findViewById(R.id.llReformInfo);
        etDataCollect=findViewById(R.id.etDataCollect);
        etHiddenTitle=findViewById(R.id.etHiddenTitle);
        llAsseessDepart=findViewById(R.id.llAsseessDepart);
        tvHiddendDangerType=findViewById(R.id.tvHiddendDangerType);
        rcPic=findViewById(R.id.rcPic);
        llReform=findViewById(R.id.llReform);
        llHiddenDangerInfo=findViewById(R.id.llHiddenDangerInfo);
        tvGetPast=findViewById(R.id.tvGetPast);
        llReformPerson=findViewById(R.id.llReformPerson);
        tvReformDate=findViewById(R.id.tvReformDate);
        llAcceptPerson=findViewById(R.id.llAcceptPerson);
        tvHiddendDangerName=findViewById(R.id.tvHiddendDangerName);
        llAcceptDepart=findViewById(R.id.llAcceptDepart);
        tvSubmit=findViewById(R.id.tvSubmit);
        tvNoGetPast=findViewById(R.id.tvNoGetPast);
        tvHiddendDanger=findViewById(R.id.tvHiddendDanger);
        tvAcceptPerson=findViewById(R.id.tvAcceptPerson);
        llReformDate=findViewById(R.id.llReformDate);
        tvNoRelative=findViewById(R.id.tvNoRelative);
        tvAssessPerson=findViewById(R.id.tvAssessPerson);
        llAssessPerson=findViewById(R.id.llAssessPerson);
        tvAsseessDepart=findViewById(R.id.tvAsseessDepart);
        tvReformDate1=findViewById(R.id.tvReformDate1);
        llReformDepart=findViewById(R.id.llReformDepart);
        etRemark=findViewById(R.id.etRemark);
        llReformDate1=findViewById(R.id.llReformDate1);
        tvReformPerson=findViewById(R.id.tvReformPerson);
        tvReformDepart=findViewById(R.id.tvReformDepart);
        tvAcceptDepart=findViewById(R.id.tvAcceptDepart);
        llHiddendangerType=findViewById(R.id.llHiddendangerType);
        tvHiddendDangerLevel=findViewById(R.id.tvHiddendDangerLevel);
        llHiddenLevel=findViewById(R.id.llHiddenLevel);
        llHiddenLevel.setOnClickListener(this::onClick);
        llReformDate1.setOnClickListener(this::onClick);
        llHiddendangerType.setOnClickListener(this::onClick);
        llAsseessDepart.setOnClickListener(this::onClick);
        llAcceptDepart.setOnClickListener(this::onClick);
        tvSubmit.setOnClickListener(this::onClick);
        tvNoRelative.setOnClickListener(this::onClick);
        llReformPerson.setOnClickListener(this::onClick);
        tvHiddendDanger.setOnClickListener(this::onClick);
        llReformDepart.setOnClickListener(this::onClick);
        llAcceptPerson.setOnClickListener(this::onClick);
        tvNoGetPast.setOnClickListener(this::onClick);
        tvGetPast.setOnClickListener(this::onClick);
        llAssessPerson.setOnClickListener(this::onClick);
        llReformDate.setOnClickListener(this::onClick);

        etRemark.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                remark=s.toString().trim();
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        etDataCollect.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                dataCollect=s.toString().trim();
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        etHiddenTitle.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                hdangerTitle=s.toString().trim();
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        tvGetPast.setTextColor(getResources().getColor(R.color.blue_3B5BEA));
        tvGetPast.setBackgroundResource(R.drawable.blue_bg_3_selecter_selected);
        tvHiddendDangerName.setText(name);

        imagesUrl=new ArrayList<>();
        managers=new GridLayoutManager(getContext(),3);
        rcPic.setLayoutManager(managers);
        adapter=new HiddenDangerImageAdapter(imagesUrl, HiddenDangerAdd.this);
        rcPic.setHasFixedSize(true);
        rcPic.setAdapter(adapter);
        adapter.setClickListener(new HiddenDangerImageAdapter.OnItemClickListener() {
            @Override
            public void onClick(View view, int position) {
                //添加
                PictureSelector
                        .create(HiddenDangerAdd.this)
                        .openGallery(PictureMimeType.ofImage())
                        .selectionMode(PictureConfig.MULTIPLE)
                        .isCamera(true)
                       // .selectionData(imagesUrl)
                        .maxSelectNum(3)
                        .compressQuality(100)
                        .loadImageEngine(GlideEngine.createGlideEngine())
                        .forResult(PictureConfig.CHOOSE_REQUEST);
            }

            @Override
            public void onSelected(View view, int position) {
                switch (view.getId()){
                    case R.id.ivClear:
                        //删除当前图片
                        imagesUrl.remove(position);
                        adapter.notifyDataSetChanged();
                        break;
                }
            }
        });
        getUserInfo();
    }

    public void submitData(){
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("checkTableId",checkTableId);
            jsonObject.put("defRecordId",defRecordId);
            jsonObject.put("result",type);
            jsonObject.put("riskName",name);
            jsonObject.put("checkAddress",checkAddress);

            if (UserData.create(HiddenDangerAdd.this).get(UserData.ls_ps).equals("1")){
                if (type==2){
                    if (hdangerTitle.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请填写隐患标题！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("hdangerTitle",hdangerTitle);

                    if (hdangerLevel.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请填写隐患等级！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("hdangerLevel",hdangerLevel);

                    if (reviewDepartId.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请选择评审部门！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("reviewDepartId",reviewDepartId);

                    if (reviewPersonId.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请选择评审人员！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("reviewPersonId",reviewPersonId);

                    if (reviewTime.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请选择评审日期！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("reviewTime",reviewTime);

                    if (hdangerType.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请选择隐患类型！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("hdangerType",hdangerType);
                }
            }else {
                if (type==2){
                    if (hdangerTitle.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请填写隐患标题！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("hdangerTitle",hdangerTitle);

                    if (hdangerLevel.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请填写隐患等级！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("hdangerLevel",hdangerLevel);
                    if (hdangerType.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请选择隐患类型！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("hdangerType",hdangerType);

                    if (rectPersonId.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请选择整改人！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("rectPersonId",rectPersonId);


                    if (rectDepartId.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请选择整改部门！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("rectDepartId",rectDepartId);

                    if (acceptDepartId.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请选择验收部门！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("acceptDepartId",acceptDepartId);

                    if (acceptPersonId.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请选择验收人！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("acceptPersonId",acceptPersonId);

                    if (allottedTime.equals("")){
                        Toast.makeText(HiddenDangerAdd.this,"请选择整改时间！！",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    jsonObject.put("allottedTime",allottedTime);
                }
            }

            if (!remark.equals("")){
                jsonObject.put("remark",remark);
            }

            if (!itemImg.equals("")){
                jsonObject.put("itemImg",itemImg.substring(0,itemImg.length()-1));
            }

            if (!dataCollect.equals("")){
                jsonObject.put("dataCollect",dataCollect);
            }

            jsonObject.put("itemId",itemId);
            jsonObject.put("riskPointId",riskPointId);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        new HttpRequest(this).doPost(UrlConstants.checkcheckOption, null,jsonObject, new HttpStringCallBack() {
            @RequiresApi(api = Build.VERSION_CODES.M)
            @Override
            public void onSuccess(Object result) {
                String datas = result.toString();
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject(datas);
                    String message = jsonObject.getString("message");
                    Boolean success = jsonObject.getBoolean("success");
                    if (success) {
                        Object obj = JsonUtils.fromJson(result.toString(), BaseModel.class);
                        if (obj instanceof BaseModel) {
                            Intent intent=getIntent();
                            intent.putExtra("type",type);
                            setResult(RESULT_OK, intent);
                            finish();
                        }
                    }else {
                        Toast.makeText(HiddenDangerAdd.this,message,Toast.LENGTH_SHORT).show();
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int code, String msg) { }
        });
    }

    public void reSetStatus(){
        tvGetPast.setBackgroundResource(R.drawable.stoke_gray_bg_5);
        tvNoGetPast.setBackgroundResource(R.drawable.stoke_gray_bg_5);
        tvNoRelative.setBackgroundResource(R.drawable.stoke_gray_bg_5);
        tvHiddendDanger.setBackgroundResource(R.drawable.stoke_gray_bg_5);
        tvHiddendDanger.setTextColor(getResources().getColor(R.color.gray9));
        tvNoRelative.setTextColor(getResources().getColor(R.color.gray9));
        tvNoGetPast.setTextColor(getResources().getColor(R.color.gray9));
        tvGetPast.setTextColor(getResources().getColor(R.color.gray9));
        llHiddenDangerInfo.setVisibility(View.GONE);
        llReformInfo.setVisibility(View.GONE);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode==RESULT_OK){
            if (requestCode==REQUESTCODE){
                reviewDepartId=data.getStringExtra("id");
                tvAsseessDepart.setText(data.getStringExtra("name"));
            }else if(requestCode==REQUESTCODE1){
                reviewPersonId=data.getStringExtra("id");
                tvAssessPerson.setText(data.getStringExtra("name"));
            }else if(requestCode==REQUESTCODE2){
                tvHiddendDangerLevel.setText(data.getStringExtra("name"));
                hdangerLevel=data.getStringExtra("type");
            }else if(requestCode==REQUESTCODE3){
                tvHiddendDangerType.setText(data.getStringExtra("name"));
                hdangerType=data.getStringExtra("id");
            } else if(requestCode==REQUESTCODE4){
                tvReformDepart.setText(data.getStringExtra("name"));
                rectDepartId=data.getStringExtra("id");
            }else if(requestCode==REQUESTCODE5){
                tvReformPerson.setText(data.getStringExtra("name"));
                rectPersonId=data.getStringExtra("id");
            } else if(requestCode==REQUESTCODE6){
                tvAcceptDepart.setText(data.getStringExtra("name"));
                acceptDepartId=data.getStringExtra("id");
            } else if(requestCode==REQUESTCODE7){
                tvAcceptPerson.setText(data.getStringExtra("name"));
                acceptPersonId=data.getStringExtra("id");
            }else if (requestCode== PictureConfig.CHOOSE_REQUEST) {
                // 结果回调
                //获取oss  token
                List<LocalMedia> cameraList = PictureSelector.obtainMultipleResult(data);
                imagesUrl.clear();
                for (int i = 0; i < cameraList.size(); i++) {
                    imagesUrl.add(cameraList.get(i).getRealPath());
                }
                adapter.notifyDataSetChanged();
            }
        }
    }

    @Override
    protected int getTitleBarType() {
        return 0;
    }
}
